package TinyURL的加密与解密535;

import java.util.HashMap;

/**
 * @author 谢阳
 * @version 1.8.0_131
 */
class Codec {
    private HashMap<String,String> hashMap = new HashMap<>();
    // Encodes a URL to a shortened URL.
    public String encode(String longUrl) {
        String code = longUrl.hashCode()+ "";
        hashMap.put(code,longUrl);
        return "http://tinyurl.com/" + code;
    }

    // Decodes a shortened URL to its original URL.
    public String decode(String shortUrl) {
        String decode = shortUrl.substring(shortUrl.lastIndexOf("/") + 1);
        return hashMap.get(decode);
    }
}

// Your Codec object will be instantiated and called as such:
// Codec codec = new Codec();
// codec.decode(codec.encode(url));
